var t = getApp();
var QQMapWX = require("../../../we7/resource/js/qqmap-wx-jssdk.min.js");
var demo = new QQMapWX({
  key: 'CTDBZ-OTHRU-OQXVA-2OYYH-VOIE5-BZB3O' // 必填
});
Page({
  data: {
    jjdd:false,
    oo:0,
    pg:0,
    ckList:[],
    ckListw:[],
    ckLists:[],
    dd:0,
    ykj:'***',
    dz:[],
    zj:false,
    user:[],//个人信息
    phone:'',//手机号
    qwjg:'',//期望价格
    indicatorDots: !1,
    autoplay: !1,
    interval: 5e3,
    duration: 1e3,
    id: 0,
    carInfo: [],
    isShow: !1,
    follow_status: !1,
    swiperCurrent: 1,
    lunboLength: 0,
    imgUrls: [],
    share_id: 0,
    modleBlock: 0,
    mengcengBlock: 0,
    modleBlock1: 0,
    mengcengBlock1: 0,
    unitid: 123,
    appscene: 0,
    isvip:2
  },
  changblock: function(t) {
    console.log(t.detail.current), this.setData({
      swiperCurrent: 1 + t.detail.current
    });
  },
  mengceng_Block: function() {
    this.setData({
      mengcengBlock: 1,
      modleBlock: 1
    });
  },
  jc:function(e){
    console.log(e)
    var dd = e.currentTarget.dataset.dd
    this.setData({
      dd:dd
    })

  },
  mengceng_none: function() {
    this.setData({
      modleBlock: 0
    });
    var t = this;
    setTimeout(function() {
      t.setData({
        mengcengBlock: 0
      });
    }, 700);
  },
  mengceng_Block1: function() {
    this.setData({
      mengcengBlock1: 1,
      modleBlock1: 1
    });
  },
  ykj:function(){
    var that = this
    that.setData({
      ykj: that.data.carInfo.low_price
    })
  },
  mengceng_none1: function() {
    this.setData({
      modleBlock1: 0
    });
    var t = this;
    setTimeout(function() {
      t.setData({
        mengcengBlock1: 0
      });
    }, 700);
  },
  onLoad: function(a) {
    console.log('aaaaaaaaaaaaaaa',a)
    var abb = this;
    t.util.request({
      url: "entry/wxapp/Api",
      data: {
        m: "monai_market",
        r: "extends.damage",
        id:a.id
      },
      success: function (t) {
        var ckListw = t.data.data.exterior
        var ckLists = t.data.data.structure
        console.log('ttttttttttttt', t)
        if(t.data.data.length==0){
          console.log('ssssssssssssssssssssssssssssssssssssssssssssss')
          abb.setData({
            jjdd:true
          })
        }else{
         
          var b = 0
          for (let i = 0; i < ckListw.length; i++) {
            if (ckListw[i].val != '0') {
              b++
              ckListw[i].nub = b
            }

          }
          var c = 0
          for (let i = 0; i < ckLists.length; i++) {
            if (ckLists[i].val != '0') {
              c++
              ckLists[i].nub = c
            }
          }
          abb.setData({
            ckList: t.data.data,
            ckListw: ckListw,
            ckLists: ckLists,
            oo: b,
            pg: c
          })
        }
        }
        
    });
    this.setData({
      isvip: t.globalData.vip
    })
    console.log(t.data.appscene), 1007 != t.data.appscene && 1008 != t.data.appscene && 1011 != t.data.appscene && 1012 != t.data.appscene && 1013 != t.data.appscene && 1014 != t.data.appscene || this.setData({
      appscene: 1
    }), this.setData({
      lunboLength: this.data.imgUrls.length
    });
    var e = 0,
      n = decodeURIComponent(a.scene);
    console.log(n), n > 0 ? e = n : a.id > 0 && (e = a.id), this.data.id = e, this._car_info(),
      this._info_set(0);
  },
  _info_set: function() {
    var a = this;
    t.util.request({
      url: "entry/wxapp/Api",
      data: {
        m: "monai_market",
        r: "home.index.info_set"
      },
      cachetime: "0",
      success: function(t) {
        console.log(t), 2 == t.data.data.flow_set && "" != t.data.data.flow_set_id && a.setData({
          unitid: t.data.data.flow_set_id
        });
      }
    });
  },
  _car_info: function() {
    var a = this;
    t.util.request({
      url: "entry/wxapp/Api",
      data: {
        m: "monai_market",
        r: "home.index.car_info",
        id: this.data.id,
        uid: wx.getStorageSync("uid")
      },
      cachetime: "0",
      success: function(t) {
        console.log('t')
        console.log(t)
        console.log('t')
        demo.geocoder({
          address: t.data.data.address ,
          success: function (res) {
            console.log(res);
            a.setData({
              dz: res.result.location
            })
          },
          fail: function (res) {
            console.log(res);
          },
          complete: function (res) {
            console.log(res);
          }
        });
        var e = !1;
        if (t.data.data.follow && t.data.data.follow.length > 0) {
          var n = !0,
            i = !1,
            o = void 0;
          try {
            for (var s, r = t.data.data.follow[Symbol.iterator](); !(n = (s = r.next()).done); n = !0)
              if (s.value.uid == wx.getStorageSync("uid")) {
                e = !0;
                break;
              }
          } catch (t) {
            i = !0, o = t;
          } finally {
            try {
              !n && r.return && r.return();
            } finally {
              if (i) throw o;
            }
          }
        }
        var c = [],
          u = !0,
          d = !1,
          l = void 0;
        try {
          for (var f, g = t.data.data.image[Symbol.iterator](); !(u = (f = g.next()).done); u = !0) {
            var h = f.value;
            c.push(h.img_patch);
          }
        } catch (t) {
          d = !0, l = t;
        } finally {
          try {
            !u && g.return && g.return();
          } finally {
            if (d) throw l;
          }
        }
        a.setData({
          carInfo: t.data.data,
          phone: t.data.data.user.phone,
          follow_status: e,
          imgUrls: c,
          user:t.data.data.user
        });
        if (wx.getStorageSync("uid") == t.data.data.uid){
          a.setData({
            zj:true
          })
        }
      },
      fail: function() {
        wx.showModal({
          title: "提示",
          content: "该商品或已下架！",
          showCancel: !1,
          success: function(t) {
            t.confirm && wx.navigateBack({});
          }
        });
      }
    });
  },
  daikuan: function() {
    wx.navigateTo({
      url: "/pages/loan/index?carid=" + this.data.id
    });
  },
  hideDialog: function() {
    this.setData({
      isShow: !this.data.isShow
    });
  },
  home: function() {
    wx.switchTab({
      url: "/pages/index/index"
    });
  },
  updateUserInfo: function(a) {
    var e = this;
    t.util.getUserInfo(function(t) {
      wx.setStorageSync("uid", t.memberInfo.uid), e.hideDialog();
    }, a.detail);
  },
  onShareAppMessage: function(t) {
    return {
      title: this.data.carInfo.name,
      path: "/pages/home/carMessage/carMessage?id=" + this.data.id + "&share_id=1",
      success: function(t) {},
      fail: function(t) {}
    };
  },
  tel: function() {
    wx.makePhoneCall({
      phoneNumber: this.data.carInfo.phone,
      success: function() {}
    });
  },
  follow: function() {
    var a = this;
    t.util.getUserInfo(function(t) {
      t.memberInfo || that.setData({
        isShow: !0
      });
    }), t.util.request({
      url: "entry/wxapp/Api",
      data: {
        m: "monai_market",
        r: "me.follow",
        uid: t.getuid(),
        type: 2,
        ucar_id: this.data.carInfo.id
      },
      cachetime: "0",
      success: function(t) {
        a.setData({
          follow_status: !a.data.follow_status,
          follow: t.data.data
        });
      }
    });
  },
  yan: function(a) {
    var e = t.getAttr(a, "form_type");
    wx.navigateTo({
      url: "/pages/home/jubao/jubao?car_uid=" + this.data.carInfo.uid + "&form_type=" + e + "&car_id=" + this.data.id
    });
  },
  store: function(a) {
    var e = t.getAttr(a, "uid");
    wx.navigateTo({
      url: "../../store/index?uid=" + e
    });
  },
  detile: function(a) {
    var e = t.getAttr(a, "id");
    wx.navigateTo({
      url: "/pages/home/carMessage/carMessage?id=" + e
    });
  },
  company: function(a) {
    var e = t.getAttr(a, "x"),
      n = t.getAttr(a, "y"),
      i = t.getAttr(a, "name");
    e && n && wx.getLocation({
      type: "gcj02",
      success: function(t) {
        wx.openLocation({
          latitude: parseFloat(e),
          longitude: parseFloat(n),
          scale: 14,
          name: i
        });
      }
    });
  },
  previewImage: function(a) {
    var e = t.getAttr(a, "src"),
      n = [],
      i = !0,
      o = !1,
      s = void 0;
    try {
      for (var r, c = this.data.carInfo.image[Symbol.iterator](); !(i = (r = c.next()).done); i = !0) {
        var u = r.value;
        n.push(u.img_patch);
      }
    } catch (t) {
      o = !0, s = t;
    } finally {
      try {
        !i && c.return && c.return();
      } finally {
        if (o) throw s;
      }
    }
    wx.previewImage({
      current: e,
      urls: n
    });
  },
  imgs: function(a) {
    var e = t.getAttr(a, "src"),
      n = this.data.imgUrls;
    wx.previewImage({
      current: e,
      urls: n
    });
  },
  tomap: function() {
    var t = this;
    wx.getSetting({
      success: function(a) {
        a.authSetting["scope.userLocation"] ? wx.chooseLocation({
          success: function(a) {
            t.setData({
              mapx: a.latitude,
              mapy: a.longitude,
              mapname: a.address + a.name
            });
          }
        }) : wx.showModal({
          content: "请允许获取地理位置后再次尝试",
          success: function(t) {
            t.confirm ? wx.openSetting({}) : t.cancel && console.log("用户点击取消");
          }
        });
      }
    });
  },
  poster: function(t) {
    wx.navigateTo({
      url: "../poster/index?carid=" + this.data.carInfo.id
    });
  },
  shouyewdj_btn: function() {
    console.log(123), wx.switchTab({
      url: "/pages/index/index"
    }), t.data.appscene = 0;
  },
  lxfs:function(e){
    console.log(e)
    var dd = e.detail.value
    this.setData({
      phone:dd
    })
  },
  qwjg: function (e) {
    console.log(e)
    var dd = e.detail.value
    this.setData({
      qwjg:dd
    })
  },
  tj:function(e){
    console.log(e);
    var that = this
    console.log(wx.getStorageSync("uid"));
    t.util.request({
      url: "entry/wxapp/Api",
      data: {
        m: "monai_market",
        r: "extends.offer",
        id: this.data.carInfo.id,
        uid: wx.getStorageSync("uid"),
        phone: this.data.phone ,
        money: this.data.qwjg,
        touid: this.data.carInfo.uid,
      },
      success:(tt)=> {
        var tt = tt.data
        if (tt.errno == 0){
         
          this.setData({
            mengcengBlock1:0
          });
          wx.showToast({
            title: "报价成功",
            duration: 2000
          })
          console.log(this.data.mengcengBlock1)
        }else{
          wx.showToast({
            title: tt.message,
            icon: "none",
            duration: 2000
          })
        }
      }
    });
  }
});